<template>
  <ElPupFormBox :pup="pupAdd" isBg :isFoot="isEdit" @closeBtn="closeBtn">
    <template #default="{ form }">
      <CellBox title="基础信息" isTop>
        <FlexBox :list="4">
          <ElFormItemBox label="产品名称" :prop="`productName`">
            <ElInputBox :data="pup" dataName="productName" disabled />
          </ElFormItemBox>
          <ElFormItemBox label="产品编码" :prop="`productNumber`">
            <ElInputBox :data="form.baseData" dataName="productNumber" disabled />
          </ElFormItemBox>
          <ElFormItemBox label="客户名称" :prop="`customerName`">
            <ElInputBox :data="form.baseData" dataName="customerName" disabled />
          </ElFormItemBox>
          <ElFormItemBox label="工艺名称" :prop="`craftName`">
            <ElInputBox :data="form.baseData" dataName="craftName" disabled />
          </ElFormItemBox>
          <ElFormItemBox label="版筒轮号" :prop="`sBanTongLunHao`">
            <ElInputBox :data="form.baseData" dataName="sBanTongLunHao" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="印刷跳距" :prop="`sYinShuaTiaoJu`">
            <ElInputBox :data="form.baseData" dataName="sYinShuaTiaoJu" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="模切跳距" :prop="`sMoQieTiaoJu`">
            <ElInputBox :data="form.baseData" dataName="sMoQieTiaoJu" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="虚刀" :prop="`sXuDao`">
            <ElInputBox :data="form.baseData" dataName="sXuDao" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="复合" :prop="`sFuHe`">
            <ElInputBox :data="form.baseData" dataName="sFuHe" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="胶面印刷" :prop="`sJiaoMianYinShua`">
            <ElInputBox :data="form.baseData" dataName="sJiaoMianYinShua" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="烫金" :prop="`sTangJin`">
            <ElInputBox :data="form.baseData" dataName="sTangJin" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="覆膜" :prop="`sFuMo`">
            <ElInputBox :data="form.baseData" dataName="sFuMo" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="光油" :prop="`sGuangYou`">
            <ElInputBox :data="form.baseData" dataName="sGuangYou" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="喷码" :prop="`sPenMa`">
            <ElInputBox :data="form.baseData" dataName="sPenMa" :disabled='!isEdit' />
          </ElFormItemBox>
          <ElFormItemBox label="杀胶" :prop="`sShaJiao`">
            <ElInputBox :data="form.baseData" dataName="sShaJiao" :disabled='!isEdit' />
          </ElFormItemBox>
        </FlexBox>
      </CellBox>
      <CellBox title="客户品质要求" isTop>
        <template v-for="item in options.require">
          <el-checkbox v-model="form.baseData[item.value]" :label="item.label" :disabled='!isEdit' />
        </template>
      </CellBox>
      <CellBox title="机台信息" isTop>
        <TableBoxMx :data="{
          disabled: !isEdit,
          tbody: form.machineData,
          thead: [
            {
              label: '适用机台',
              prop: 'machineCode',
              align: 'center',
              width: null,
              formType: 'select',
              options: options.machine,
            },
            {
              label: '预调机时间',
              prop: 'pretreatmentTime',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '建议速度',
              prop: 'recommendedSpeed',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '出卷张力',
              prop: 'coilingTension',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '收卷张力',
              prop: 'windingTension',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '覆卷张力',
              prop: 'coilTension',
              align: 'left',
              width: 160,
              formType: 'text'
            },
          ],
          add: {
            productTechniqueCardCode: form.baseData.productTechniqueCardCode, //关联的产品工艺卡code
            productTechniqueCardMachineID: 0, //主键
            productTechniqueCardMachineCode: '', //唯一编码
            machineCode: '', //关联的机台code
            pretreatmentTime: '', //预调机时间
            recommendedSpeed: '', //建议速度
            coilingTension: '', //出卷张力
            windingTension: '', //收卷张力
            coilTension: '' //覆卷张力
          },
          operation: [
            {
              label: '删除',
              icon: 'Delete',
            }
          ]
        }">
        </TableBoxMx>
      </CellBox>
      <CellBox title="油墨配方" isTop>
        <TableBoxMx :data="{
          disabled: !isEdit,
          tbody: form.inkData,
          thead: [
            {
              label: '颜色名称',
              prop: 'colorName',
              align: 'center',
              width: 160,
              formType: 'text'
            },
            {
              label: '油墨代号',
              prop: 'inkCodeName',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '油墨配比',
              prop: 'inkRatio',
              align: 'left',
              width: null,
              formType: 'text'
            },
            {
              label: '胶水克重',
              prop: 'glueWeight',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '网纹辊线数',
              prop: 'aniloxRollsQuantity',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '目数',
              prop: 'meshQuantity',
              align: 'left',
              width: 160,
              formType: 'text'
            },
            {
              label: '供应商',
              prop: 'supplier',
              align: 'left',
              width: null,
              formType: 'text'
            },
          ],
          add: {
            productTechniqueCardCode: form.baseData.productTechniqueCardCode, //关联的产品工艺卡code
            productTechniqueCardInkID: 0, // 主键
            productTechniqueCardInkCode: '', // 唯一编码
            colorName: '', // 颜色名称
            inkCodeName: '', // 油墨代号
            inkRatio: '', // 油墨配比
            aniloxRollsQuantity: '', // 网纹辊线数
            meshQuantity: '', // 目数
            supplier: '', // 供应商
            glueWeight: '' // 胶水克重
          },
          operation: [
            {
              label: '删除',
              icon: 'Delete',
            }
          ]
        }">
        </TableBoxMx>
      </CellBox>
      <CellBox title="材料信息" isTop>
        <TableBoxMx :data="{
          tbody: form.materialData,
          thead: [
            {
              label: '规格编号',
              prop: 'specificationCode',
              align: 'center',
              width: 160,
            },
            {
              label: '物料名称',
              prop: 'goodsName',
              align: 'left',
              width: null,
            },
            {
              label: '规格型号',
              prop: 'specificationName',
              align: 'left',
              width: 160,
            },
            {
              label: '物料类型',
              prop: 'goodsCategoryName',
              align: 'center',
              width: 160,
            },
          ],
        }">
        </TableBoxMx>
      </CellBox>
    </template>
  </ElPupFormBox>

</template>
<script setup lang="ts">
import '../pageCss.scss'; // 引入样式
const { proxy } = getCurrentInstance() as any;
const props = withDefaults(
  defineProps<{
    pup?: any;//数据源
    isEdit?: boolean;//是否編輯
    options?: any;//数据组
    setState?: Function;//更改状态
  }>(),
  {
  },
);
watch(() => props.pup.state, (newVal, oldVal) => {
  if (props.pup.state) {
    openPup()
  }
});
const options: any = reactive({
  machine: [],
  require: [
    {
      label: '条码扫读',
      value: 'scanBarcode',
    },
    {
      label: '着墨性测试',
      value: 'testInkability',
    },
    {
      label: '耐磨测试',
      value: 'testAbrasion',
    },
    {
      label: '高低温测试',
      value: 'testTemperature',
    },
    {
      label: '耐酒精测试',
      value: 'testAlcohol',
    },
    {
      label: '粘性测试',
      value: 'testStickiness',
    },
    {
      label: '其它',
      value: 'other',
    },
  ]
})
const isEdit = ref(true)
const openPup = () => {
  pupAdd.loading = true
  proxy.$api.OrderBusniess.GetProductTechniqueCardDetails({
    productTechniqueCode: props.pup.productTechniqueCode,
  })
    .then((res: any) => {
      pupAdd.form = res
      pupAdd.loading = false
      isEdit.value = res.baseData.isLocked !== 1
      GetSingleProductCraft(res.baseData.craftCode)
      proxy.$openPup(pupAdd, 2)
    }).catch(() => {

    })
}
//获取工艺信息
const GetSingleProductCraft = (craftCode: string) => {
  proxy.$api.ProductCraft.GetSingleProductCraft({
    queryBy: 0, // 工艺名称
    queryValue: craftCode, // 工艺名称
  }).then((res: any) => {
    pupAdd.form.baseData.craftName = res.name
  });
}
const pupAdd: any = reactive({
  state: false,
  typeName: 0,
  title: `工艺资料卡`,
  form: {
    baseData: {
      productTechniqueCardID: 0, // 主键
      productTechniqueCardCode: "", // 唯一编码
      productTechniqueCode: "", // 关联的产品工艺code
      craftCode: "", // 关联的工艺code（冗余）
      deviceCode: "", // 关联的机台code（冗余）
      productCode: "", // 关联的产品code（冗余）
      sBanTongLunHao: "", // 版筒轮号
      sYinShuaTiaoJu: "", // 印刷跳距
      sMoQieTiaoJu: "", // 模切跳距
      sXuDao: "", // 虚刀
      sFuHe: "", // 复合
      sJiaoMianYinShua: "", // 胶面印刷
      sTangJin: "", // 烫金
      sFuMo: "", // 覆膜
      sGuangYou: "", // 光油
      sPenMa: "", // 喷码
      sShaJiao: "", // 杀胶
      scanBarcode: false, // 条码扫读
      testInkability: false, // 着墨性测试
      testAbrasion: false, // 耐磨测试
      testTemperature: false, // 高低温测试
      testAlcohol: false, // 耐酒精测试
      testStickiness: false, // 粘性测试
      other: false, // 其它
      isLocked: 0, // 是否锁定
      customerName: "", // 客户名称
      productNumber: "" // 产品编号
    },
    machineData: [
      {
        productTechniqueCardMachineID: 0, // 主键
        productTechniqueCardMachineCode: "", // 唯一编码
        productTechniqueCardCode: "", // 关联的产品工艺卡code
        machineCode: "", // 关联的机台code
        pretreatmentTime: "", // 预调机时间
        recommendedSpeed: "", // 建议速度
        coilingTension: "", // 出卷张力
        windingTension: "", // 收卷张力
        coilTension: "", // 覆卷张力
        machineName: "" // 机台名称
      }
    ],
    materialData: [
      {
        productTechniqueCardMaterialID: 0, // 主键
        productTechniqueCardMaterialCode: "", // 唯一编码
        productTechniqueCardCode: "", // 关联的产品工艺卡code
        goodsCode: "", // 物料code
        specificationCode: "", // 物料规格code
        supplierCode: "", // 供应商code
        thickness: "", // 厚度
        specificationName: "", // 规格名称
        goodsName: "", // 物料名称
        supplierName: "", // 供应商名称
        goodsCategoryName: "" // 物料类型名称
      }
    ],
    inkData: [
      {
        productTechniqueCardInkID: 0, // 主键
        productTechniqueCardInkCode: "", // 唯一编码
        productTechniqueCardCode: "", // 关联的产品工艺卡code
        colorName: "", // 颜色名称
        inkCodeName: "", // 油墨代号
        inkRatio: "", // 油墨配比
        aniloxRollsQuantity: "", // 网纹辊线数
        meshQuantity: "", // 目数
        supplier: "", // 供应商
        glueWeight: "" // 胶水克重
      }
    ]
  },
  btns: [
    {
      title: '保存',
      type: 'primary',
      click: (pup: any) => {
        pup.loading = true
        //新建
        proxy.$api.OrderBusniess.UpdateProductTechniqueCard(pup.form)
          .then((res: any) => {
            saveBtn()
            closeBtn()
            pup.state = false
            proxy.$message(`保存成功`);
          }).catch(() => {
            pup.loading = false
          })
      }
    }
  ]
});
const closeBtn = () => {
  props.pup.state = false
}
const saveBtn = () => {
  emit('saveBtn')
}
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'saveBtn'): void;
}>();
import { getMachine } from '@/utils/optionsArr.ts';
onMounted(() => {
  getMachine(options, 'machine')
});
</script>
